local skel = fk.CreateSkill {
  name = "efengqi__guicai",
}

Fk:loadTranslationTable{
  ["efengqi__guicai"] = "鬼才",
  [":efengqi__guicai"] = "当一名角色的判定牌生效前，你可以打出一名角色一张牌替代之，然后其可以对你造成1点伤害。",

  ["#efengqi__guicai_select"] = "鬼才",
  ["#efengqi__guicai-choose"] = "鬼才：你可以打出一名角色的一张牌代替 %dest 进行“%arg”判定的判定牌%arg2",
  ["#efengqi__guicai-damage"] = "鬼才：你可以对 %src 造成1点伤害",

  ["$efengqi__guicai1"] = "天命难违？哈哈哈哈哈……",
  ["$efengqi__guicai2"] = "才通天地，逆天改命！",
}

skel:addEffect(fk.AskForRetrial, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p) return not p:isNude() end)
    if #targets == 0 then return false end
    -- 打出别人的牌暂时不判合法性吧……
    local success, dat = room:askToUseActiveSkill(player, {
      skill_name = "#efengqi__guicai_select", prompt = "#efengqi__guicai-choose::"..target.id..":"..data.reason..":"..data.card:toLogString(),
    })
    if success and dat then
      local tos, cards = dat.targets, dat.cards
      if #tos == 0 then
        tos = {player}
      else
        cards = {room:askToChooseCard(player, { target = tos[1], flag = "he", skill_name = skel.name })}
      end
      event:setCostData(self, {tos = tos, cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local cards = event:getCostData(self).cards
    room:changeJudge({
      data = data, card = Fk:getCardById(cards[1]), player = player, skillName = skel.name, response = true,
    })
    if not to.dead and not player.dead and room:askToSkillInvoke(to, { skill_name = skel.name,
     prompt = "#efengqi__guicai-damage:"..player.id}) then
      room:doIndicate(to, {player})
      room:damage { from = to, to = player, damage = 1, skillName = skel.name }
    end
  end,
})



return skel
